package com.qk.management.controller;

import com.qk.common.util.PageResult;
import com.qk.common.util.Result;
import com.qk.dto.acticity.ActivityDto;
import com.qk.entity.Activity;
import com.qk.management.anno.LogOperation;
import com.qk.management.service.ActivityService;
import com.qk.vo.ActivityVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/activities")
public class ActivityController {
    @Autowired
    private ActivityService activityService;
    @GetMapping
    public Result getActivity(ActivityDto activityDto) {
        log.info("分页查询活动：{}", activityDto);
        PageResult<ActivityVO> activitypageResult = activityService.getActivity(activityDto);
        return Result.success(activitypageResult);
    }
    @DeleteMapping("/{id}")
    @LogOperation
    public Result deleteActivity(@PathVariable("id") Integer activityid) {
        log.info("删除活动：{}", activityid);
        activityService.deleteActivity(activityid);
        return Result.success();
    }
    @PostMapping
    @LogOperation
    public Result addActivity(@RequestBody Activity activity) {
        log.info("添加活动：{}", activity);
        activityService.addActivity(activity);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result selectById(@PathVariable("id") Integer activityid) {
        log.info("根据ID查询活动：{}", activityid);
        Activity activity = activityService.selectById(activityid);
        return Result.success(activity);
    }
    @PutMapping
    @LogOperation
    public Result updateActivity(@RequestBody Activity activity) {
        log.info("修改活动：{}", activity);
        activityService.updateActivity(activity);
        return Result.success();
    }
    @GetMapping("/type/{type}")
    public Result selectByType(@PathVariable("type") Integer type) {
        log.info("查询类型下所有活动：{}", type);
        List<ActivityVO> activityList = activityService.selectByType(type);
        return Result.success(activityList);
    }
}
